package day06;

import java.util.Arrays;

public class HomeWork {
    public static void main(String[] args) {
        int[] arr = new int[10];
        int max = 0;
        System.out.println("添加最大值之前");
        for (int i = 0; i < arr.length; i++) {
            arr[i] = (int) (Math.random() * 100 + 1);
            System.out.print(arr[i]+" ");
            if (max < arr[i]) {
                max = arr[i];
            }

        }
        arr = Arrays.copyOf(arr, arr.length + 1);
        arr[arr.length - 1] = max;
        System.out.println();
        System.out.println("添加最大值之后");
        for (int i = 0; i < arr.length; i++) {
            System.out.print(arr[i]+" ");
        }
        System.out.println();

        System.out.println("使用say方法");
        say();

        System.out.println("使用sayHi方法");
        sayHi("zhangsan");

        System.out.println("使用sayHello方法");
        sayHello("lisi", "你今天吃了吗");

        System.out.println("使用getNum方法");
        int num = getNum();
        System.out.println(num);

        int plus = plus(5, 6);
        System.out.println("使用方法plus");
        System.out.println(plus);
        System.out.println("使用方法随机长度为10的数组");
        int[] arr2 = testArray(10);
        for (int j : arr2) {
            System.out.print(j + " ");
        }
        System.out.println();

        System.out.println("使用方法随机长度为10的数组");
        int[] array = testArray(10);
        int maxOfArray = getMaxOfArray(array);
        for (int i:array){
            System.out.print(i+" ");
        }
        System.out.println();
        System.out.println("使用方法找出最大值");
        System.out.println(maxOfArray);

    }

    public static void say() {
        System.out.println("你好");
    }

    public static void sayHi(String name) {
        System.out.println(name + "你好");
    }

    public static void sayHello(String name, String question) {
        System.out.println(name + "你好," + question);
    }

    public static int getNum() {
        return 6;
    }

    public static int plus(int a, int b) {

        return a + b;
    }

    public static int[] testArray(int a) {
        int[] arr = new int[a];
        for (int i = 0; i < arr.length; i++) {
            arr[i] = (int) (Math.random() * 100 + 1);

        }
        return arr;
    }

    public static int getMaxOfArray(int[] arr){
        int max = 0;
        for (int i = 0; i < arr.length; i++) {
            if (max < arr[i]) {
                max = arr[i];
            }
        }
        return max ;
    }
}
